package n15.second;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.stream.Collectors;

public class F02 {
	public static void main(String[] args) throws IOException {
		Path path = Paths.get("./src/n15/second/article.txt");
		Map<Character, Long> map = Files.lines(path, Charset.forName("utf-8"))
			.flatMap(s->s.chars().mapToObj(c->(char)c))
			.filter(Character::isLetter)
			.map(Character::toLowerCase)
			.collect(Collectors.groupingBy(c->c, Collectors.counting()));
		map.entrySet().stream()
			.sorted(Map.Entry.<Character, Long>comparingByValue().reversed())
			.forEach(e->System.out.println(e.getKey()+"\t"+e.getValue()));		
	}
}
